package com.lc.spring.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyInterceptor {
	@Pointcut("execution(* com.lc.spring.aop.service.UserService.*(..))")
	private void anyMethod() {
		System.out.println("AnyMethod");
	}// 定义一个切入点

	@Before("anyMethod()")
	public void doAccessCheck() {
		System.out.println("前置通知");
	}

	@AfterReturning("anyMethod()")
	public void doAfter() {
		System.out.println("后置通知");
	}

	@After("anyMethod()")
	public void after() {
		System.out.println("最终通知");
	}

	@AfterThrowing("anyMethod()")
	public void doAfterThrow() {
		System.out.println("例外通知");
	}

	@Around("anyMethod()")
	public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
		System.out.println("进入环绕通知");
		Object object = pjp.proceed();// 执行该方法
		System.out.println("退出方法");
		return object;
	}

	// // before通知方法
	// public void beforeShow() {
	// System.out.println(getClass().toString() + " before show");
	// }
	//
	// // after通知方法
	// public void afterShow() {
	// System.out.println(getClass().toString() + " after show");
	// }
	//
	// // afterReturn通知方法
	// public void afterReturnShow() {
	// System.out.println(getClass().toString() + " afterReturn show");
	// }
	//
	// // afterThrowing通知方法
	// public void afterThrowingShow() {
	// System.out.println(getClass().toString() + " afterThrowing show");
	// }
	//
	// // around通知方法
	// public void aroundShow(ProceedingJoinPoint jpoint) {
	//
	// try {
	// System.out.println(getClass().toString() + " around before show");
	// // 执行目标对象的连接点处的方法
	// jpoint.proceed();
	// System.out.println(getClass().toString() + " around after show");
	// } catch (Throwable e) {
	// System.out.println(getClass().toString() + " around afterThrowing show");
	// }
	// }
}
